"""
代码库数据模型
"""
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, JSON
from sqlalchemy.sql import func
from database import Base


class Repository(Base):
    """代码库模型"""
    __tablename__ = "repositories"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String(255), nullable=False, comment="代码库名称")
    url = Column(String(500), nullable=False, comment="代码库URL")
    platform = Column(String(50), nullable=False, comment="平台类型")
    auth_type = Column(String(50), nullable=False, comment="认证类型")
    auth_info = Column(JSON, nullable=False, comment="认证信息")
    is_source = Column(Boolean, default=False, comment="是否为源代码库")
    status = Column(String(50), default="disconnected", comment="连接状态")
    last_verified = Column(DateTime(timezone=True), comment="最后验证时间")
    created_at = Column(DateTime(timezone=True), server_default=func.now(), comment="创建时间")
    updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), comment="更新时间")